#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,i,j,n,s1,s2,k;
	cin>>n;
	for(i=2;i<=n;i++)
	{
		k=i/2,s1=0,s2=0;
		for(j=2;j<=k;j++)
			if(i%j==0)
				s1=s1+j;
		if(s1==i)
			continue;
		else 
		{
			k=s1/2;
			for(j=2;j<=k;j++)
				if(s1%j==0)
					s2=s2+j;
			if(s2==i&&s1<=n)
				printf("%d %d\n",i,s1);
		}
	}
    return 0;
}
